﻿using STMS.Models.VModels;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace STMS.DAL
{
    public class ViewStoreRegionDAL:BQuery<ViewStoreRegionInfo>
    {
        /// <summary>
        /// 条件查询仓库分区列表
        /// </summary>
        /// <param name="storeId"></param>
        /// <param name="temperState"></param>
        /// <param name="keywords"></param>
        /// <param name="isDeleted"></param>
        /// <returns></returns>
        public List<ViewStoreRegionInfo> GetStoreRegionList(int storeId,int temperState,string keywords,int isDeleted)
        {
            List<ViewStoreRegionInfo> list = new List<ViewStoreRegionInfo>();
            string strWhere = $"isDeleted={isDeleted}";
            string cols = CreateSql.GetColsString<ViewStoreRegionInfo>("IsDeleted");
            SqlParameter paraKeywords = null;
            if (storeId>0)
            {
                strWhere += $" and StoreId={storeId}";
            }
            if (temperState > -1)
                strWhere += $" and TemperState={temperState}";
            if (!string.IsNullOrEmpty(keywords))
            {
                strWhere += " and (SRegionName like @keywords or SRegionNo like @keywords)";
                paraKeywords = new SqlParameter(" @keywords", $"%{keywords}%");
                list = GetModelList(strWhere, cols, paraKeywords);
            }
            else
                list = GetModelList(strWhere, cols);

            return list;
        }
    }
}
